package com.CST.controller.cb;

import com.CST.common.api.Response;
import com.CST.common.api.ResultObject;
import com.CST.dto.cb.BdPerformanceDTO;
import com.CST.entity.cb.BdDepartment;
import com.CST.entity.cb.BdOrganization;
import com.CST.entity.cb.BdPerformance;
import com.CST.mapper.dataplatform.BdDepartmentMapper;
import com.CST.service.cb.IBdPerformanceService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author qtx
 * @since 2023-05-16
 */
@Api(tags = {"绩效科室对照"})
@RestController
@RequestMapping("/bdPerformance")
public class BdPerformanceController {

    @Autowired
    private IBdPerformanceService  bdPerformanceService;

    @Autowired
    private BdDepartmentMapper bdDepartmentMapper;

    @GetMapping("/getPDepartment")
    @ApiOperation("科室下拉框")
    public ResultObject getPDepartment(String  DeptName,String DeptCode) {
        List<BdDepartment> pDepartment = bdDepartmentMapper.getPDepartment(DeptName,DeptCode);
        return ResultObject.success(pDepartment);
    }

    @GetMapping("/getDepartment")
    @ApiOperation("部门下拉框")
    public ResultObject getDepartment(String  DeptName,String DeptCode) {
        List<BdDepartment> getDepartment = bdDepartmentMapper.getDepartment(DeptName,DeptCode);
        return ResultObject.success(getDepartment);
    }

    @PostMapping("/addPerformance")
    @ApiOperation("添加科室部门对应数据")
    public ResultObject addPerformance(@RequestBody BdPerformance entity) {
        Response result = bdPerformanceService.addPerformance(entity);
        return ResultObject.resultReturn(result);
    }



    @PostMapping("/modifyPerformance")
    @ApiOperation("修改科室部门对应数据")
    public ResultObject modifyOrganization(@RequestBody BdPerformance entity) {

        Response result = bdPerformanceService.modifyPerformance(entity);
        return ResultObject.resultReturn(result);
    }




    @PostMapping("/batchDeletePerformance")
    @ApiOperation("删除对应关系, 传id 多个以逗号隔开")
    public ResultObject batchDeletePerformance(@RequestBody List<Integer> ids) {
        if (ids == null || ids.stream().count() == 0) {
            return ResultObject.errorReturn("请选择要删除的记录");
        }
        Response result = bdPerformanceService.batchDeletePerformance(ids);
        return ResultObject.resultReturn(result);
    }



    @PostMapping("/getBdPerformance")
    @ApiOperation("获取科室对应关系")
    public ResultObject getBdPerformance(@RequestBody BdPerformanceDTO bdPerformanceDTO) {

        IPage<BdPerformance> bdPerformance = bdPerformanceService.getBdPerformance(bdPerformanceDTO);
        return ResultObject.success(bdPerformance);
    }


    @GetMapping("/getDepartmentSourceWithPerformance")
    @ApiOperation("获取科室绩效字典")
    public ResultObject getDepartmentSourceWithPerformance() {

        List<BdDepartment> departmentSourceWithPerformance = bdPerformanceService.getDepartmentSourceWithPerformance();
        return ResultObject.success(departmentSourceWithPerformance);
    }

    @GetMapping("/getDeptCodeBdDepartments")
    @ApiOperation("绩效his对照下拉框科室下拉框")
    public ResultObject getDeptCodeBdDepartments() {
        List<BdDepartment> deptCodeBdDepartments = bdPerformanceService.getDeptCodeBdDepartments();
        return ResultObject.success(deptCodeBdDepartments);
    }


}
